package me.chan.functional;

public class AppMain {

	public static void main(String[] args) {
	
		//MyList<Integer> list = new MyLinkedList<>(5, new MyLinkedList<Integer>(10, new Empty<>()));
	/*	LazyList<Integer> numbers = from(2);
		int two = numbers.head();
		System.out.println(two);
		int three = numbers.tail().head();
		System.out.println(three);
		int four = numbers.tail().tail().head();
		System.out.println(four);*/
		LazyList<Integer> gt2 = from(2);
		MyList<Integer> primers = primes(gt2);
		printAll(primers);		//StackOverflow
	}
	
	public static LazyList<Integer> from(Integer n) {
		return new LazyList<Integer>(n, () -> from(n + 1));
	}
	
	public static MyList<Integer> primes(MyList<Integer> numbers) {
		return new LazyList<>(
					numbers.head(), 
					() -> numbers.tail().filter( num -> num % numbers.head() != 0 )
				);
	}
	
	public static <T> void printAll(MyList<T> list) {
		if (list.isEmpty()) {
			return ;
		}
		System.out.println(list.head());
		printAll(list.tail());
	}
}
